# Maintainer: David Runge <dvzrv@archlinux.org>

_name=crispy-bootstrap4
pkgname=python-crispy-bootstrap4
pkgver=2022.1
pkgrel=2
pkgdesc="Bootstrap4 template pack for django-crispy-forms"
arch=(any)
url="https://github.com/django-crispy-forms/crispy-bootstrap4"
license=(MIT)
# prevent circular deps: https://github.com/django-crispy-forms/crispy-bootstrap4/issues/7
depends=(
  python
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(
  python-django
  python-django-crispy-forms
  python-pytest
  python-pytest-django
)
# no tests in sdist tarball: https://github.com/django-crispy-forms/crispy-bootstrap4/issues/8
# source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz)
source=($url/archive/$pkgver/$_name-$pkgver.tar.gz)
sha256sums=('8c26fa5fa7d388d873e13b97fc91b206d8d2398c9b3627d7c0d9b28767f137b4')
b2sums=('573847b614b5f6cf71fea6ed6831eeef48ac01b2c2db07653d600b5b0829209188d235a143585ed4fabb663264aff3b5f7a416d99d12a8e268d4c62edaf3db84')

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$site_packages:$PWD:$PYTHONPATH"
  pytest -vv tests
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 {CHANGELOG,README}.md -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
